home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / vectlib.exe / VECT3.H < prev    next >
C/C++ Source or Header  |  1991-07-25  |  2KB  |  64 lines

  1. //vector3.h, By Scott Litvinoff
  2. //3-D vector class definition and useful vector funcs. (ascii to vector, etc.)
  3.  
  4. #include "stdlib.h"
  5. #include "float.h"
  6. #include "iostream.h"
  7. #include "math.h"
  8. #include "string.h"
  9.  
  10. class vector3
  11. {
  12.     double xp,yp,zp;    //In rectangular coordinate form
  13.  
  14.     public:
  15.     vector3(double xpd=0,double ypd=0,double zpd=0)  //Constructor
  16.     {                                                //If no parameters given,
  17.         xp=xpd;                                      //defaults to the
  18.         yp=ypd;                                      //null vector
  19.         zp=zpd;
  20.     }
  21.  
  22.     friend vector3 operator+(vector3&,vector3&);     // Binary vector addition
  23.  
  24.  
  25.     friend vector3 operator*(vector3&,vector3&);     // Vector product
  26.                                                      //  (Cross Product)
  27.  
  28.     friend double operator|(vector3&,vector3&);      // Vector Dot Product
  29.  
  30.  
  31.     friend vector3 operator-(vector3&,vector3&);     // Binary Vector Subtraction
  32.  
  33.  
  34.     friend vector3 operator-(vector3&);              // Unary vector negation
  35.  
  36.  
  37.     friend vector3 operator+(vector3&);              // Unary vector addition
  38.                                                      //  (Returns same as input)
  39.  
  40.     friend vector3 operator*(double,vector3&);       // Scalar Multiplication of
  41.                                                      //  Vector
  42.  
  43.     friend vector3 operator*(vector3&,double);       // Scalar Multiplication of
  44.                                                      //  Vector
  45.     void print()
  46.     {
  47.         cout<<"("<<xp<<","<<yp<<","<<zp<<")";        // Output a vector
  48.     }
  49.     double x()
  50.     {
  51.         return xp;                                   // Returns x component
  52.     }
  53.     double y()
  54.     {
  55.         return yp;                                   // Returns y component
  56.     }
  57.     double z()
  58.     {
  59.         return zp;                                   // Returns z component
  60.     }
  61. };
  62.  
  63. vector3 atov(char *);                                // Ascii to vector
  64.